// Eric Lorenz, Matt Rodano, Thomas Bradley
// SSW-567, Spring 2010, Professor Laird
// Assignment 2: Triangle Program

#include <iostream>
using namespace std;


double validateString(string str)
    {
        double length;
        char * pEnd;
        char c_str[5];
         
        strcpy (c_str, str.c_str());
        length = strtod(c_str, &pEnd);
        
        if (length == 0.0)
           cout<<"\nNot a valid number! ";
           
        if (errno == ERANGE)
        {
           cout<<"\nNumber out of range! ";
           length = -999.0;
        }
           
        if (length < 0.0)
           cout<<"\nPositive numbers only! ";
           
        if (length >= 1001)
        {
           cout<<"\nNumber must be less than 1001! ";
           length = -99.0;
        }
           
        return length;              
    }

int main()
{
// Delcarations
     string side_length;
     double s1 = -1.0, s2 = -1.0, s3 = -1.0;
     
// Input
     while(s1 <= 0.0)
     {
          cout<<"Please enter the length of side 1: ";
          cin>>side_length;
     
          s1 = validateString(side_length);
     }
          
     while(s2 <= 0.0)
     {
          cout<<"Please enter the length of side 2: ";
          cin>>side_length;
     
          s2 = validateString(side_length);
     }
     
     while(s3 <= 0.0)
     {
          cout<<"Please enter the length of side 3: ";
          cin>>side_length;
     
          s3 = validateString(side_length);
     }
  
//Output
   
     cout<<"\n\nThis is a";
    
     if(s1==s2 && s2==s3)
          cout<<"n Equilateral ";

     if( (s1==s2 && s2!=s3) || (s2==s3 && s3!=s1) || (s3==s1 && s1!=s2) )
          cout<<"n Isosceles ";
     
     if(s1!=s2 && s2!=s3 && s3!=s1)
          cout<<" Scalene ";
          
     if( ((s1*s1 + s2*s2) == s3*s3) || ((s1*s1 + s3*s3) == s2*s2) || ((s2*s2 + s3*s3) == s1*s1) )
          cout<<"Right ";
          
     cout<<"Triangle.";
          

     cout<<"\n\n";
     system("pause");
                    
     return 0;     
     
}
